package com.qumitech.visualnovel.service.userexpand.impl;

import com.alibaba.fastjson.JSONObject;
import com.qumitech.visualnovel.component.util.HttpInvokeUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.datasource.console.UserExpandMapper;
import com.qumitech.visualnovel.model.common.UrlConstant;
import com.qumitech.visualnovel.pubdef.dto.expandProfit.ExpandProfitDTO;
import com.qumitech.visualnovel.pubdef.dto.expandProfit.ExpandProfitDetailDTO;
import com.qumitech.visualnovel.service.userexpand.UserExpandService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserExpandServiceImpl implements UserExpandService {

    @Autowired
    UserExpandMapper userExpandMapper;

    @Override
    public BaseRsp listRelation(Map<String, String> reqMap) {

        String url = UrlConstant.SERVER_URL + "/admin/user/expand/relation";
        String body = HttpInvokeUtil.httpGet(url, reqMap, null);
        return JSONObject.parseObject(body, BaseRsp.class);
    }

    @Override
    public BaseRsp listProfit(Long accountId, Long minProfit, Long maxProfit, String startTime, String endTime, String orderBy, String orderType, Integer offset, Integer limit) {
        List<ExpandProfitDTO> userExpandProfit = userExpandMapper.listUserExpandProfit(accountId, minProfit, maxProfit, startTime, endTime, orderBy, orderType, offset, limit);
        Integer count = userExpandMapper.countUserExpandProfit(accountId, minProfit, maxProfit, startTime, endTime);
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("count", count, "data", userExpandProfit));
    }

    @Override
    public BaseRsp listProfitDetail(Long masterUid, Long fellowUid, String startTime, String endTime, Integer offset, Integer limit) {
        List<ExpandProfitDetailDTO> userExpandProfitDetail = userExpandMapper.listUserExpandProfitDetail(masterUid, fellowUid, startTime, endTime, offset, limit);
        Integer count = userExpandMapper.countUserExpandProfitDetail(masterUid, fellowUid, startTime, endTime);
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("count", count, "data", userExpandProfitDetail));
    }

}
